##! /bin/bash
#! bash
#
#  $Id: to_db_import.sh 3 2010-05-27 16:25:49Z alistair.mills@btinternet.com $
#

### Main script stars here ###
# Store file name  here
export     FILE=$1
export   OUTPUT=$2
export    total=0
. ./defines.sh
. ./keys.sh
rm      $OUTPUT
touch   $OUTPUT
while read year mon cat size url key trans line
do
  if [ "$line" != "$title_line" -a "$year" != "$comment_line" ]
  then
    export    INPUT=${year}_${mon}_${cat}.htm
    if [ "$line" != "" -a "$key" = "$done"  -a -f $INPUT ]
    then
      export       total=`expr $total + 1`
      export         tot=`printf '%.3i' $total`
      echo Found $key: $tot - $INPUT - $line
      output=""
      export change_date=`cat $last$INPUT`
      while read line2
      do
        export line3=`echo $line2 | sed 's/"/\&quot;/g'`
        output="$output $line3"
      done < $INPUT
      echo "$year;$mon;$cat;$size;$url;\""$change_date"\";$key;$trans;\""$line"\";\"$output\"" >> $OUTPUT
    fi
  fi
done < $FILE
#
#
#
